<!DOCTYPE html>
<html>
{% load staticfiles %}
<head>
<meta charset=utf-8"utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>玩客狗</title>
<script src="{% static 'js/jquery.min.js' %}"></script>


<script src="{% static 'js/jquery-weui.min.js' %}"></script>
<link href="{% static 'css/app.2b1339aa8b4bf34ca660f39fbcc8078b.css' %}" rel="stylesheet">
<link href="{% static 'css/jquery-weui.min.css' %}" rel="stylesheet">
</head>
<body>
<div id="app">
	<div data-v-5a6e21d0="" class="page"  style="background: #000D16 url({% static 'image/bg2.jpg' %}) no-repeat;">
		<div data-v-5a6e21d0="" id="login">
			<div data-v-5a6e21d0="" class="logo">
				<img data-v-5a6e21d0="" src="{% static 'image/logo.png' %}"  style="border-radius:0;">
				<p data-v-5a6e21d0="">
					玩客狗				</p>
			</div>
			<div data-v-5a6e21d0="">
				<div class="weui-cells vux-no-group-title">
					<div data-v-5a6e21d0="" class="vux-x-input weui-cell" id="mobileCell">
						<div class="weui-cell__hd">
						</div>
						<div class="weui-cell__bd weui-cell__primary">
							<input id="vux-x-input-uo99r" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" type="tel" pattern="[0-9]*" placeholder="请输入手机号" class="weui-input">
						</div>
						<div class="weui-cell__ft">
							<i class="weui-icon weui_icon_clear weui-icon-clear" style="display: none;"></i><i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" title="" style="display: none;"></i><i class="weui-icon weui_icon_success weui-icon-success" style="display: none;"></i>
						</div>
					</div>
					<div data-v-5a6e21d0="" class="vux-x-input weui-cell" id="passwordCell" style="display: none;">
						<div class="weui-cell__hd">
						</div>
						<div class="weui-cell__bd weui-cell__primary">
							<input id="vux-x-input-32pqz" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" type="password" placeholder="请输入密码" class="weui-input">
						</div>
						<div class="weui-cell__ft">
							<i class="weui-icon weui_icon_clear weui-icon-clear" style="display: none;"></i><i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" title="" style="display: none;"></i><i class="weui-icon weui_icon_success weui-icon-success" style="display: none;"></i>
						</div>
					</div>
					<div data-v-5a6e21d0="" class="vux-x-input weui-cell weui-vcode" id="vcodeCell" style="display: none;">
						<div class="weui-cell__hd">
						</div>
						<div class="weui-cell__bd weui-cell__primary">
							<input id="vux-x-input-sd6d1" maxlength="6" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" type="number" placeholder="输入验证码" class="weui-input">
						</div>
						<div class="weui-cell__ft">
							<i class="weui-icon weui_icon_clear weui-icon-clear" style="display: none;"></i><i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" title="" style="display: none;"></i><i class="weui-icon weui_icon_success weui-icon-success" style="display: none;"></i><button data-v-5a6e21d0="" class="weui-btn weui-btn_mini weui-btn_primary" id="sendCode">发送验证码</button>
						</div>
					</div>
					<div data-v-5a6e21d0="" class="vux-x-input weui-cell" id="newpwdCell" style="display: none;">
						<div class="weui-cell__hd">
						</div>
						<div class="weui-cell__bd weui-cell__primary">
							<input id="vux-x-input-suvrw" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" type="password" placeholder="请设置密码（长度6~18位）" class="weui-input">
						</div>
						<div class="weui-cell__ft">
							<i class="weui-icon weui_icon_clear weui-icon-clear" style="display: none;"></i><i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" title="" style="display: none;"></i><i class="weui-icon weui_icon_success weui-icon-success" style="display: none;"></i>
						</div>
					</div>
				</div>
			</div>
			<div data-v-5a6e21d0="" style="margin: 20px 0px;">
				<button data-v-5a6e21d0="" disabled="disabled" class="weui-btn weui-btn_disabled weui-btn_default" id="nextBtn">下一步</button>
				<p data-v-5a6e21d0="" class="terms" id="termsLink">
					点击下一步即表示你已同意 <a data-v-5a6e21d0="" href="javascript:if(confirm('请仔细阅读'))window.location='/terms'" class="">《用户协议》</a>
				</p>
				<button data-v-5a6e21d0="" class="weui-btn weui-btn_default" id="loginBtn" style="display: none;">登录</button>
			</div>
			<div data-v-5a6e21d0="" class="more" style="display: none;">
				<div data-v-5a6e21d0="">忘记密码</div>
			</div>
		</div>
	</div>
</div>
<script>

         $(document).ready(function() {


        	function getUrlParam(k) {
    var regExp = new RegExp('([?]|&)' + k + '=([^&]*)(&|$)');
    var result = window.location.href.match(regExp);
    if (result) {
        return decodeURIComponent(result[2]);
    } else {
        return null;
    }
    }

    id = getUrlParam ('id')

    })






var actionFlag = '';

$(function(){
	$("#vux-x-input-uo99r").on('input',function(e){
		if($(this).val() != ''){
			$(this).parent().next().find('.weui-icon-clear').show();
			if(!(/^1[34578]\d{9}$/.test($(this).val()))){
				$(this).parent().next().find('.weui-icon-warn').show();
				$('#nextBtn').addClass('weui-btn_disabled');
				$('#nextBtn').attr("disabled",true);
			}
			else{
				$(this).parent().next().find('.weui-icon-warn').hide();
				//$(this).parent().next().find('.weui-icon-success').show();
				$('#nextBtn').removeClass('weui-btn_disabled');
				$('#nextBtn').attr("disabled",false); 
			}
		}
		else{
			$(this).parent().next().find('.weui-icon-clear').hide();
			$(this).parent().next().find('.weui-icon-warn').hide();
			//$(this).parent().next().find('.weui-icon-success').hide();
		}
	});

	$('#vux-x-input-32pqz,#vux-x-input-sd6d1,#vux-x-input-suvrw').on('input',function(e){
		var value = $(this).val();
		if(value != ''){
			$(this).parent().next().find('.weui-icon-clear').show();
			if(value.length < 6){
				$(this).parent().next().find('.weui-icon-warn').show();
			}
			else{
				$(this).parent().next().find('.weui-icon-warn').hide();
				//$(this).parent().next().find('.weui-icon-success').show();
			}
		}
		else{
			$(this).parent().next().find('.weui-icon-clear').hide();
			$(this).parent().next().find('.weui-icon-warn').hide();
			//$(this).parent().next().find('.weui-icon-success').hide();
		}
	});

	$('.weui-icon-clear').click(function(){
		$(this).parent().prev().find('input').val('');
		$(this).hide();
		$(this).parent().find('.weui-icon-warn').hide();
		//$(this).parent().find('.weui-icon-success').hide();
	});

	{#输入框右边的小圆点#}
	$('.weui-icon-warn').click(function(){
		var type = $(this).parent().prev().find('input').attr('type');
		if(type == 'tel'){
			$.toast("手机号码格式不对哦~","text");
		}
		else if(type == 'password'){
			$.toast("密码格式不符合要求","text");
		}
		else if(type == 'number'){
			$.toast("最少应该输入6个字符哦","text");
		}
	});



	{# 手机号是注册还是登入接口#}

    $.ajaxSetup({
        data:{csrfmiddlewaretoken:'{{ csrf_token }}'},
    });

	$('#nextBtn').click(function(){
	    {#id2 = getUrlParam(id)#}


		$.post("{% url 'check_mobile' %}", { "mobile": $('#vux-x-input-uo99r').val()  },
			function(data){
				if(data.code == 0){
					$.toast(data.msg,"text");
				}
				else{
					if(data.msg == 'need_login'){
						actionFlag = 'login';
						$('#mobileCell').show();
						$('#passwordCell').show();
						$('#vcodeCell').hide();
						$('#newpwdCell').hide();
						$('#nextBtn').hide();
						$('#termsLink').hide();
						$('#loginBtn').text('登录');
						$('#loginBtn').show();
						$('.more').show();
					}
					else if(data.msg == 'need_register'){
						actionFlag = 'register';
						$('#mobileCell').show();
						$('#passwordCell').hide();
						$('#vcodeCell').show();
						$('#newpwdCell').show();
						$('#nextBtn').hide();
						$('#termsLink').hide();
						$('#loginBtn').text('注册');
						$('#loginBtn').show();
						$('.more').hide();
					}
				}
		}, "json");
	});

	$('.more').click(function(){
		actionFlag = 'findpwd';
		$('#mobileCell').show();
		$('#passwordCell').hide();
		$('#vcodeCell').show();
		$('#newpwdCell').show();
		$('#nextBtn').hide();
		$('#termsLink').hide();
		$('#loginBtn').text('重置密码');
		$('#loginBtn').show();
		$('.more').hide();
	});
     $.ajaxSetup({
        data:{csrfmiddlewaretoken:'{{ csrf_token }}'},
    });


	$('#sendCode').click(function(){
		$.post("{% url "send_sms" %}", { "mobile": $('#vux-x-input-uo99r').val() },
			function(data){
				if(data.code == 0){
					$.toast(data.msg,"text");
				}
				else{
					$('#sendCode').addClass('weui-btn_disabled');
					$('#sendCode').attr("disabled",true); 
					curCount = count;
					$('#sendCode').text("重新发送"+curCount);
					InterValObj = window.setInterval(SetRemainTime, 1000);
				}
		}, "json");
	});


    $.ajaxSetup({
        data:{csrfmiddlewaretoken:'{{ csrf_token }}'},
    });
	$('#loginBtn').click(function(){

		$.post("{% url "do_login" %}", { "mobile": $('#vux-x-input-uo99r').val(), "password": $('#vux-x-input-32pqz').val(),"vcode": $('#vux-x-input-sd6d1').val(),"newpassword": $('#vux-x-input-suvrw').val(),   "id":id , "actionflag": actionFlag},
			function(data){
				if(data.code == 0){
					$.toast(data.msg,"text");
				}

				else{
					if(data.code == 1){

				    location.href = '{% url 'user' %}';
				    }
				}
		}, "json");
	});

}); 

var InterValObj; 
var count = 60; 
var curCount;

function SetRemainTime() { 
	if (curCount == 0) {         
		window.clearInterval(InterValObj);//停止计时器 
		$("#sendCode").removeClass("weui-btn_disabled");
		$("#sendCode").attr("disabled",false); 
		$("#sendCode").text("发送验证码"); 
	} 
	else { 
		curCount--; 
		$("#sendCode").text("重新发送"+curCount); 
	} 
}

</script>

</body>
</html>